<template>
  <div class="home">
    <el-container class="home-container">
      <!-- 头部区域 -->
      <el-header>
        <h1>电商后台管理系统</h1>   
        <el-button type="info" @click="logout" class="tui">退出</el-button>
      </el-header>
      <!-- 页面主体区域 -->
      <el-container>
        <!-- 侧边栏 -->
        <el-aside :width="this.isCollapse ? '65px':'200px'">
          <div class="toggle-b" @click="toggleB" >|||</div>
         <el-menu
            router
            unique-opened
            :collapse="isCollapse"
            :collapse-transition="false"
            background-color="#333744"
            text-color="#fff"
            active-text-color="#ffd04b">
            <!-- 一级菜单 -->
            <el-submenu :index="item.id+''"  v-for="item in menulist" :key="item.id">
              <template slot="title">
                <i :class="iconsObj[item.id]"></i>
                <span>{{item.authName}}</span>
              </template>
              <el-menu-item  :index="'/' + subItem.path"  v-for="subItem in item.children" 
							:key="subItem.id" @click="saveNav('/'+subItem.path)">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{subItem.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
            
          </el-menu>
        </el-aside>
          
        <!-- 主体结构 -->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
// @ is an alias to /src


export default {
  name: 'Home',
  data(){
    return {
      aPath:'',
      menulist:[],
      iconsObj: {
        125: 'el-icon-user',
        103: 'el-icon-s-custom',
        101: 'el-icon-goods',
        102: 'el-icon-s-finance',
        145: 'el-icon-s-marketing',
      },
      isCollapse:false,
    }
  },
  components:{
   
  },
  created(){
   this.getMenuList()
  },
  methods:{
    logout(){
      window.sessionStorage.removeItem("token");
      this.$router.push("/login")
    },
    async getMenuList(){
      const {data:res} = await this.$http.get("menus");
      if(res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.menulist = res.data;
    },
    toggleB(){
      this.isCollapse = !this.isCollapse
    },
    saveNav(aPath){
       window.sessionStorage.setItem("path",aPath);
       this.path = aPath;
    }
  }
}
</script>
<style lang="less" scoped>
  .home{
    height: 100%;
  }
  .home-container{
    height: 100%;
  }
  .el-header{
    background-color:cadetblue;
  }
  .el-aside{
    background-color: #333743;
  }
  .el-main{
    background-color: darkgoldenrod;
  }
  .el-header{
    float: left;
    line-height: 60px;
  }
  h1{
    display: inline;
  }
  .tui{
    float: right;
    display: flex;
    margin-top: 10px;
  }
  .toggle-b{
    text-align: center;
    color: #fff;
  }
</style> 